<?php

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
//接受表单数据
if(@$_GET['action']=='post'){
    $_clean=array();
    $_clean['tg_name']=$_POST['name'];
    $_clean['tg_mingzu']=$_POST['mingzu'];
    $_clean['tg_chusheng']=$_POST['chusheng'];
    $_clean['tg_age']=$_POST['age'];
    $_clean['tg_sex']=$_POST['sex'];
    $_conn=  mysql_connect('localhost','root','')or die ('连接数据库失败!');
    mysql_select_db('school',$_conn)or die ('连接数据表失败!');
    mysql_query('SET NAMES UTF8')or die ('字符集错误!');
    mysql_query("INSERT INTO tg_table (tg_name,tg_mingzu,tg_chusheng,tg_age,tg_sex,tg_date) 
                               VALUES('{$_clean['tg_name']}',
                                      '{$_clean['tg_mingzu']}',  
                                      '{$_clean['tg_chusheng']}',
                                      '{$_clean['tg_age']}',
                                      '{$_clean['tg_sex']}',
                                      NOW()
                                                          
                                   
               )")or die (mysql_error());
    
   if(mysql_affected_rows()==1){
       echo"<script type='text/javascript'>alert('添加成功');location.href='table.php';</script>";
   }else{
       echo"<script type='text/javascript'>alert('添加失败');location.href='table.php';</script>";
   }
    
}
?>
<html>
    <head>
        <title>表单保存</title>  
        <link rel="stylesheet" type="html/css" href="style/table.css"/>
   </head>
   <body>
       <h3 id="h3">请认真填写以下内容</h3>
       <div id="table">
           <form method="post" action="?action=post">
           <ul>
               <li>姓　　名:<input type="text" name="name" class="text"/><li>
               <li>名　　族:<input type="text" name="mingzu" class="text"/><li> 
               <li>出生日期:<input type="text" name="chusheng" class="text"/><li>
               <li>年　　龄:<input type="text" name="age" class="text"/><li>
               <li>性　　别:<input type="radio" name="sex" checked="checked" value="男"/>男<input type="radio" name="sex" value="女"/>女<li>
               <li><input type="submit" name="submit " class="submit" value="提交">
                   <a href="select.php?action=table"><input type="button" name="button " class="submit" value="查看"></a></li> 
           </ul>
            </form>
       </div> 
   </body>   
</html>